<template>
  <div class="base-content system-sampleDeliveryInfo-content">
    <div class="basic-info">
      <el-form ref="filterForm" :model="filterForm" inline>
        <el-form-item :label="dataList.ApprovalName" prop="workFlowDictcode">
          <el-select v-model="filterForm.workFlowDictcode">
            <el-option v-for="item in dictList" :key="item.dictCode" :label="item.name" :value="item.dictCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="dataList.Remark" prop="remark">
          <el-input v-model="filterForm.remark" :placeholder="dataList.SampleNumberOrRecordSlipNumber" />
        </el-form-item>
        <!-- <el-form-item label="样品编号" prop="sampleNum">
          <el-input v-model="filterForm.sampleNum"></el-input>
        </el-form-item> -->
        <el-form-item class="base-filter-button">
          <el-button v-loading="searchLoading" type="primary" @click="getList('filter')">{{ btn.Query }}</el-button>
          <el-button @click="cancelForm">{{ btn.Clear }}</el-button>
        </el-form-item>
      </el-form>
      <el-main class="roller_main">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane :label="dataList.WaittoBeDone" name="first">
            <WorkFlowSendToDo v-if="activeName == 'first'" :id.sync="filterForm.id" ref="WorkFlowSendToDo"
              :remark.sync="filterForm.remark" :work-flow-dictcode.sync="filterForm.workFlowDictcode"
              :active-name.sync="activeName" :system-type.sync="systemType" :page-info.sync="pageInfo"
              :sample-num.sync="filterForm.sampleNum" @on-change-page-info="onChangePageInfo" />
          </el-tab-pane>
          <el-tab-pane :label="dataList.HaveFinished" name="second">
            <WorkFlowSendDone v-if="activeName == 'second'" :id.sync="filterForm.id" ref="WorkFlowSendDone"
              :remark.sync="filterForm.remark" :work-flow-dictcode.sync="filterForm.workFlowDictcode"
              :sample-num.sync="filterForm.sampleNum" :active-name.sync="activeName" :system-type.sync="systemType"
              :page-info.sync="pageInfo" @on-change-page-info="onChangePageInfo" />
          </el-tab-pane>
        </el-tabs>
      </el-main>
      <!--分页-->
      <BasePagination :total="pageInfo.total" :current-page="pageInfo.pageIndex" @changePage="changePage"
        @sizeChange="sizeChange" />
    </div>
  </div>
</template>
<script>
import WorkFlowSendDone from "./WorkFlowSendDone.vue";
import WorkFlowSendToDo from "./WorkFlowSendToDo.vue";
import { SendWorkFlowStatusGetList, getDictList } from "../../api/WorkFlow/WorkFlow";
import { getConfigByKey } from "../../api/System/SystemDict";
export default {
  name: "WorkFlowSend",
  components: {
    WorkFlowSendDone,
    WorkFlowSendToDo
  },
  data() {
    return {
      systemType: '',
      searchLoading: false,
      refesh: true,
      dictList: [],
      filterForm: {
        id: 0,
        sampleNum: ''
      },
      rowList: [],
      title: "",
      activeName: "first",
      pageInfo: {
        total: 0,
        pageIndex: 1,
        pageSize: 10,
      },
    };
  },
  computed: {
    btn() {
      return this.$t("ModuleWorkFlow.buttons");
    },
    dataList() {
      return this.$t("ModuleWorkFlow.WorkFlow");
    },
  },
  created() {
    this.getDictListFun();
    // 查询字典表判断系统类型
    getConfigByKey("SystemType").then((res) => {
      this.systemType = res.data?.[0]?.value;
    });
    // 初始化数据
    if (this.$route.query.id !== undefined) {
      this.pageInfo.pageIndex = 1;
      this.filterForm.id = this.$route.query.id;

      SendWorkFlowStatusGetList({
        ...this.filterForm,
        ...this.pageInfo,
      }).then((res) => {
        if (res.data.dataList != null) {
          this.activeName = "first";
        } else {
          this.activeName = "second";
        }
      })
        .catch(() => { });
    }
  },
  methods: {

    getList() {
      if (this.activeName === "first") {
        this.$nextTick(() => {
          this.$refs.WorkFlowSendToDo.getList('filter');
        });
      } else {
        this.$nextTick(() => {
          this.$refs.WorkFlowSendDone.getList('filter');
        });
      }
    },
    getDictListFun() {
      getDictList({ dictCode: "WorkFlow" }).then(res => {
        this.dictList = res.data
      }).catch(res => {

      })
    },
    // 清空筛选条件
    cancelForm() {
      this.filterForm.id = 0;
      this.filterForm.remark = "";
      if (this.activeName === "first") {
        this.$nextTick(() => {
          this.$refs.WorkFlowSendToDo.getList('filter');
        });
      } else {
        this.$nextTick(() => {
          this.$refs.WorkFlowSendDone.getList('filter');
        });
      }
    },
    onChangePageInfo(v) {
      this.pageInfo.total = v;
    },
    handleClick() {
      this.pageInfo.pageIndex = 1;
    },
    // 切换页码
    changePage(page) {
      this.pageInfo.pageIndex = page;
      if (this.activeName === "first") {
        this.$refs.WorkFlowSendToDo.changePage();
      } else {
        this.$refs.WorkFlowSendDone.changePage();
      }
    },
    sizeChange(val) {
      this.pageInfo.pageIndex = 1;
      this.pageInfo.pageSize = val;
      if (this.activeName === "first") {
        this.$refs.WorkFlowSendToDo.sizeChange();
      } else {
        this.$refs.WorkFlowSendDone.sizeChange();
      }
    },
  },
};
</script>
